/*******************************************************************************
*   			Impacts of a Large-Scale Parenting Program: 				   *
*					Experimental Evidence from Chile						   *
********************************************************************************


	REQUIRES:	"${dt_final}panel_RR_indexes.dta"
	CREATES:	${out_tables}/T35A_heter_byhealthcenter.xls
				
	WRITEN BY:  Italo Lopez  [italolop@usc.edu]

********************************************************************************
	Prepare data
*******************************************************************************/

	* Load data
	use "${dt_final}/panel_RR_indexes.dta", clear


	* Establish macros for regressions

/*******************************************************************************
*   Set macros for regressions
*******************************************************************************/
	
	* Outcomes
	*-----------------------------------------------------------
	local childoutcomes  "zDCCSPunt zptevir_irtscore2 zt_score zcbcl_t_e zcbcl_t_i zibatt_sspi zibatt_ssai zibatt_sssr zas_raw_score" 
	local behaviors "home_score se_score disc_score" 
	local beliefs "zpstyle1 zpstyle2 zpstyle3 zPSCS zPSSS_family zPSSS_friends zPSSS_others zPSI_Distress zCESD zpacotis"	
	local child "zptevir_irtscore2 zcog_index zsoc_index" 

	* Controls
	*-----------------------------------------------------------

	macro  def Xvar1 "i.age_year i.gender"  	
	macro  def Xvar2 "i.age_year i.gender inc_qtaut_old i.pc_edu_mdsfin hh_mem hh_tipo"  	
	macro  def Xvar2old "i.gender inc_qtaut_old i.pc_edu_mdsfin_old hh_mem hh_tipo"  

	
	* Parental characteristics: WAIS and BFI and imputed wais 
	*-----------------------------------------------------------

	macro def parent_cha4 "BFI_ext BFI_ope BFI_con BFI_neu BFI_agr wais2 flag_wais"
	

/*******************************************************************************
Table A35: Heterogeneity of impact: Type of Health Center
*******************************************************************************/

forvalues num=2/3 {
	gen group`num'_familyhc=group`num'*familyhc
	gen group`num'_nofamilyhc=group`num'*(1-familyhc)
    gen group`num'_generalhc=group`num'*generalhc
	gen group`num'_nogeneralhc=group`num'*(1-generalhc)
    gen group`num'_hospital=group`num'*hospital
	gen group`num'_nohospital=group`num'*(1-hospital)
	}

local finaloutcomes "zptevir_irtscore2 zcog_index zsoc_index" 
foreach var of local finaloutcomes {

xi: xtreg `var' group2_familyhc group2_nofamilyhc familyhc group3_familyhc group3_nofamilyhc $Xvar1, fe i(CENTRO_SALUD)
estimates store `var'_fhc
test group2_familyhc - group2_nofamilyhc==0
estadd scalar p2=r(p)
test group3_familyhc - group3_nofamilyhc==0
estadd scalar p3=r(p)

xi: xtreg `var' group2_generalhc group2_nogeneralhc generalhc group3_generalhc group3_nogeneralhc $Xvar1, fe i(CENTRO_SALUD)
estimates store `var'_ghc
test group2_generalhc - group2_nogeneralhc==0
estadd scalar p2=r(p)
test group3_generalhc - group3_nogeneralhc==0
estadd scalar p3=r(p)

xi: xtreg `var' group2_hospital group2_nohospital hospital  group3_hospital  group3_nohospital  $Xvar1, fe i(CENTRO_SALUD)
estimates store `var'_hos
test group2_hospital  - group2_nohospital ==0
estadd scalar p2=r(p)
test group3_hospital  - group3_nohospital ==0
estadd scalar p3=r(p)
}

** Table A35
esttab zptevir_irtscore2_ghc zcog_index_ghc zsoc_index_ghc using "${out_tables}/appendix/T35A_heter_byhealthcenter.csv", replace f ///	   
		cells("b(fmt(3)star)" "se(fmt(3)par)") ///
	    star(* 0.10 ** 0.05 *** 0.01) ///
		stats(r2 p2 p3 N, fmt(2 3 3 0) ///
		labels("R-squared" "P-value General HC=Family HC: NEP-B" "P-value General HC=Family HC: NEP-I" "Observations")) legend ///
		keep(group2_generalhc group2_nogeneralhc  group3_generalhc group3_nogeneralhc) ///
		mtitles("Vocabulary Index" "Exec. Function Index" "Socioemotional Index" )  ///
		varlabels(group2_generalhc "NEP-B General Health" group2_nogeneralhc "NEP-B Family Health" group3_generalhc "NEP-I  General Health" group2_nogeneralhc "NEP-I  Family Health")
